home *** CD-ROM | disk | FTP | other *** search
- OVRSUB
- Version 1.0
- Ron Schuster
-
- Overview
- ----------------------------------------------------------------------------
-
- Some Turbo Pascal programmers have expressed the need to be able to use the OVR
- file from one version of a program with the EXE file from a different version
- of the same program. The following excerpt from a message from Ed Rayl
- [73210,3446] illustrates one such situation:
-
- "I have written an insurance premium finance program for a client that supports
- a standard form used by their business. I got a request to support additional
- forms as they show up. My print forms procedure is a single procedure (with
- several nested procedures) called PrintTheForm with no parameters. It grabs
- information from globals as necessary. The main .EXE is going to be
- copy-protected by Vault Corp. (yuk!) and I have no choice in this matter. The
- client would like to send one print procedure to each of their clients, based
- on the form they use. It occured to me to use an overlay for this. I would
- simply put PrintTheForm in a unit and overlay it. As new forms show up, I
- would simply replace the .OVR file with a new one. The original EXE file
- CANNOT be modified on disk. Vault does its magic by encrypting the EXE and
- then using a 'loader' program to un-encrypt it. Once it is in memory, you can
- do anything you want, however."
-
- Normally this cannot be done since the EXE file contains detailed information
- about the OVR file, and this information would be incorrect if a different
- OVR file was substituted for the original. OvrSub overcomes this
- restriction. It also lets you write a program that uses several different
- overlay files, each containing a different version of the same routines, and
- switch between them dynamically. The demo program provides an example of
- this technique. The file MAKEDEMO.BAT contains instructions for creating
- and running the demo.
-
-
- How it works
- -----------------------------------------------------------------------------
-
- Data about the overlaid units in a program, such as the location and size of
- each unit's code in the OVR file, is embedded in the EXE file in what are
- called the "static dispatchers." For more information about this, download
- the file OVRLAY.TXT from CompuServe (BPROGA lib 2). When you run the program
- OVRPREP, it extracts this data from the EXE file and appends it to the end of
- the OVR file. (I will refer to this information as the "OVRPREP data" in the
- rest of this document. The format of this data is documented in OVRPREP.PAS.)
- In the application program you must call the procedure OvrSubstitute right
- after your call to OvrInit. This reads the OVRPREP data from the end of the
- OVR file and adjusts the static dispatchers in memory. Note that the EXE file
- is never actually modified. The result of these adjustments is that calls in
- the old EXE to procedures in overlaid units find their way to the right place
- in the code contained in the new OVR file.
-
-
- Creating the OVR files
- -----------------------------------------------------------------------------
-
- The file MAKEDEMO.BAT is a brute force implementation of this approach. I
- imagine a Make utility could be used to good advantage here.
-
- 1. Add a call to OvrSubstitute after your call to OvrInit.
- 2. With the proper source code for this version in place, compile the program
- to produce EXE, OVR and MAP files.
- 3. Run OVRPREP.
- 4. Rename the OVR file with an appropriate name for this version.
- 5. Repeat steps 2 to 4 for each version of the OVR file.
-
-
- Compatibility
- -----------------------------------------------------------------------------
-
- In order for multiple versions of your OVR file to work with a single EXE
- file, they must all be "compatible." If they are not, a program crash is
- likely. Error checks are built into OvrSubstitute to try to ensure
- compatibility before proceeding with a given OVR file. Comparing reports from
- Kim Kokkonen's OVRSIZ from each OVR file version can also be useful here.
-
- To achieve compatibility, the compilation of each version of your OVR file
- should produce the same, or nearly the same, EXE file. Since each OVR file
- will ultimately be operating with one single EXE file, any references within
- the overlaid code to locations within the non-overlaid segments of the
- program must match. All but the most trivial unit will have these references,
- since these include the Data segment and the System unit.
-
- One thing that can cause trouble here is the smart linker. It may alternately
- leave in and strip out non-overlaid code during the compilation of different
- versions of the OVR file depending on what procedures are referenced in each.
-
- Another potential hazard is a difference in the "entry point count" from one
- OVR to another. The entry point count is the total number of procedures and
- functions within an overlaid unit. Ideally, each unit should have the same
- number of procedures and functions in the same order in each version of the
- OVR file. However, you may have some flexibility if you want to add one or
- two functions or procedures in one OVR that don't exist in the other. Each
- entry point adds 5 bytes to the size of the static dispatcher. Since the
- size of the segment is always rounded up to the next paragraph, there's often
- room for an extra vector or two without causing any trouble, but cross that
- boundary and you throw off the address of every segment following the
- overlaid unit. In any case, it's probably never a very good idea to change
- the interface section.
-
-
- OVRPREP
- -----------------------------------------------------------------------------
-
- OVRPREP is supplied in source form, so you'll first need to compile it to an
- EXE file. OVRPREP uses only the standard DOS unit.
-
- To use OVRPREP, first compile the overlaid application to create the EXE and
- OVR files and a corresponding MAP file. From within the TURBO integrated
- environment, you enable a MAP file with the Options/Linker/Map File/Segments
- menu. For the command line compiler, use the /GS option. OVRPREP reads only
- the first section of the MAP file (the segment map) to get certain
- information. It doesn't hurt to have a detailed MAP file, but that takes more
- time and disk space to store. OVRPREP also reads from your EXE file to get
- detailed information about the overlays. This information is then appended
- to the OVR file.
-
- Call OVRPREP as follows:
-
- OVRPREP [Options] ProgName [>Output]
-
- OVRPREP forces the extensions 'EXE', 'MAP', and 'OVR' onto ProgName to find
- the corresponding files. The only option at present is /Q, which stops OVRPREP
- from writing status messages while it works.
-
-
- The OVRSUB Unit
- -----------------------------------------------------------------------------
-
- The OVRSUB unit interfaces the functions OvrSubstitute and OvrClose. The
- OvrSubstitute function reads the OVRPREP data from the OVR file and uses it to
- adjust the static dispatchers in memory. The OvrClose function clears all
- code from the overlay buffer and closes the current OVR file. This is useful
- for dynamic overlay file switching.
-
-
- OvrSubstitute
- -----------------------------------------------------------------------------
-
- Function Reads the data appended to the OVR file by OVRPREP (the
- "OVRPREP data") and adjusts the static dispatchers in memory
- accordingly.
-
- Declaration function OvrSubstitute (CheckOverlayInfo, CheckEntryPts,
- CheckStaticSegs, CheckDataSeg : Boolean) : Word;
-
- OvrSubstitute must be called immediately after your call to OvrInit. The
- parameters enable or disable various error checks. In general, the checks
- attempt to ensure that the current OVR file is compatible with the EXE
- file that is running. If you disable any of these, you do so at your
- own risk.
-
- CheckOverlayInfo determines the result code returned by OvrSubstitute if the
- OVRPREP data is not present in the OVR file. If CheckOverlayInfo is true,
- OvrSubstitute will return an error code. Otherwise OvrSubstitute will return
- a normal completion code. Setting CheckOverlayInfo true protects against
- running the EXE file with an OVR file that has not been prepared with OVRPREP,
- which can cause a system crash if the EXE and OVR files are incompatible.
- However, this can be a nuisance during development since it requires you run
- OVRPREP after every compilation.
-
- If CheckEntryPts is true, OvrSubstitute compares the entry point counts from
- each static dispatcher to the values recorded in the OVRPREP data and
- returns an error code if any mismatch is found.
-
- If CheckStaticSegs is true, OvrSubstitute compares the segment address of the
- static dispatcher for each overlaid unit with the value recorded in the
- OVRPREP data and returns an error code if any mismatch is found.
-
- If CheckDataSeg is true, OvrSubstitute compares the address of the current
- data segment with the value recorded in the OVRPREP data and returns an
- error code if a mismatch is found.
-
-
- The following return codes are defined for OvrSubstitute:
-
- 0 Successful completion
- 1 Overlay manager not initialized. OvrInit was not called.
- 2 At least one overlaid unit already loaded in overlay buffer.
- 3 Overlay file I/O error. This may occur due to a difference in the
- number of overlaid units in the EXE and OVR files.
- 4 OVRPREP data not found in OVR file and CheckOverlayInfo is true.
- 5 Static Segment Address mismatch found and CheckStaticSegs is true.
- 6 Entry Point Count mismatch found and CheckEntryPts is true.
- 7 Data Segment mismatch found and CheckDataSeg is true.
- 8 OvrSetBuf call failed. Check the error code in OvrResult.
-
-
- OvrClose
- -----------------------------------------------------------------------------
-
- Function Clears all code from the overlay buffer and closes the
- current OVR file.
-
- Declaration function OvrClose : Word;
-
- OvrClose is useful for dynamic overlay file switching. After closing one OVR
- file, you can open another with a call to OvrInit using a different file name.
- Be sure each OvrInit call is followed by a call to OvrSubstitute.
-
- The following return codes are defined for OvrClose:
-
- 0 Successful completion
- 1 OvrDosHandle invalid or not open
-
-
- About the Programs
- -----------------------------------------------------------------------------
-
- OVRSUB was written by Ron Schuster. It is copyright (c) 1989, all rights
- reserved. It may be distributed freely, but not for a profit.
-
- OVRPREP was derived from OVRSIZ, written by Kim Kokkonen of TurboPower
- Software. It is copyright (c) 1989 by TurboPower Software, all rights
- reserved. It may be distributed freely, but not for a profit.
-
- If you have problems, suggestions, or enhancements, contact me on CompuServe
- ID [76666,2322].